package com.szd.qiongyou20.home.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.RatingBar;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.szd.qiongyou20.R;
import com.szd.qiongyou20.home.bean.CityData;

import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by SZD on 2016/12/22.
 */

public class GridView_City_Adapter extends BaseAdapter {

    private Context mContext;
    private List<CityData.DataBean.NotMissBean.PoisBean> mList;
    private LayoutInflater mInflater;

    public GridView_City_Adapter(Context context, List<CityData.DataBean.NotMissBean.PoisBean> list) {
        mContext = context;
        mList = list;
        mInflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    }

    @Override
    public int getCount() {
        return mList.size();
    }

    @Override
    public Object getItem(int position) {
        return mList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null) {
            convertView = mInflater.inflate(R.layout.item_city_not_miss, null);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        String photo = mList.get(position).getPhoto();
        String name = mList.get(position).getName();
        String price = mList.get(position).getPrice();
        String grade = mList.get(position).getGrade();
        String product_type = mList.get(position).getProduct_type();
        float f = Float.parseFloat(grade);

        Glide.with(mContext).load(photo).into(holder.mImageViewCityNotMiss);
        holder.mTextViewCityNotMiss.setText(name);
        holder.mProgressBarCityNotMiss.setRating(f / 2);
        holder.mTextViewRating.setText(grade);
        holder.mTextViewCityMoney.setText(product_type + price);

        return convertView;
    }

    static class ViewHolder {
        @Bind(R.id.imageView_city_not_miss)
        ImageView mImageViewCityNotMiss;
        @Bind(R.id.textView_city_not_miss)
        TextView mTextViewCityNotMiss;
        @Bind(R.id.progressBar_city_not_miss)
        RatingBar mProgressBarCityNotMiss;
        @Bind(R.id.textView_rating)
        TextView mTextViewRating;
        @Bind(R.id.textView_city_money)
        TextView mTextViewCityMoney;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
